package com;

import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;


import java.io.*;

/**
 * @author Zhengjz
 * @version 1.0
 * @className Main
 * @date 2020/11/3 18:44
 */
public class Main {

    public static void main(String[] args) throws Exception {

        duqvdate();

    }




    //创建一个excel文件
    public static void createExceltest() throws IOException {
        //创建一个excel文件
        HSSFWorkbook wb = new HSSFWorkbook();
        FileOutputStream fileOut = new FileOutputStream("D:\\test\\test.xls");
        // FileOutputStream fileOut= new FileOutputStream("c:/workbook.xls");
        wb.write(fileOut);
        fileOut.close();
    }


    public static void duqvdate() throws IOException, BiffException {
    int i;
    Sheet sheet;
    Workbook book;
    jxl.Cell cell1;
        jxl.Cell cell2;
        jxl.Cell cell3;
        jxl.Cell cell4;
        jxl.Cell cell5;
        jxl.Cell cell6;
        jxl.Cell cell7;
        try {
        //hello.xls为要读取的excel文件名
        book= Workbook.getWorkbook(new File("D:\\test\\test.xls"));

        //获得第一个工作表对象(ecxel中sheet的编号从0开始,0,1,2,3,....)
        sheet=book.getSheet(0);
        //获取左上角的单元格
        cell1=sheet.getCell(0,0);
        System.out.println("标题："+cell1.getContents());

        i=1;
        while(true)
        {
            //获取每一行的单元格
            cell1=sheet.getCell(0,i);//（列，行）
            cell2=sheet.getCell(1,i);
            cell3=sheet.getCell(2,i);
            cell4=sheet.getCell(3,i);
            cell5=sheet.getCell(4,i);
            cell6=sheet.getCell(5,i);
            cell7=sheet.getCell(6,i);
            if("".equals(cell1.getContents())==true)    //如果读取的数据为空
            {
                break;
            }
            System.out.println(cell1.getContents()+"\t"+cell2.getContents()+"\t"+cell3.getContents()+"\t"+cell4.getContents()
                    +"\t"+cell5.getContents()+"\t"+cell6.getContents()+"\t"+cell7.getContents());
            i++;
        }
        book.close();
    }
        catch(Exception e)  { }
    }


    public static void duqvshujv(){
        HSSFWorkbook workbook = null;
        try {
            //读取excel文件
            workbook   = new HSSFWorkbook(new FileInputStream("D:\\test\\test.xls"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        //获取sheet数目
        for(int i = 0;i<workbook.getNumberOfSheets();i++){
           HSSFSheet sheet =  workbook.getSheetAt(i);
            Row row = null;
            int lastRowNum = sheet.getLastRowNum();

            //循环读取
            for(int j = 0;j<=lastRowNum; j++){
               row = sheet.getRow(j);
               if(row != null){
                    //获取每一列的值
                   for(int t = 0;t<row.getLastCellNum();t++){
                       Cell cell = row.getCell(t);


                   }
               }
            }

        }



    }




}
